package approve.adapter;
import java.util.ArrayList;
import java.util.List;
import model.pojo.Employee;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import approve.action.R;


public class ListEmployeeAdapter  extends BaseAdapter{
	Context context;
	ArrayList<Employee> emlist= new ArrayList<Employee>();
	List<Employee> listCheck = new ArrayList<Employee>();
	String strid;
	
	public ListEmployeeAdapter(){
		
	}
	public ListEmployeeAdapter(Context context,ArrayList<Employee> emlist){
		super();
		this.emlist=emlist;
		this.context=context;
	}
	@Override
	public int getCount() {
		return emlist.size();
	}
	@Override
	public Object getItem(int position) {
		return emlist.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			LayoutInflater a=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = a.inflate(R.layout.listemployeeadapter, parent,false);
		}
		final Employee em = emlist.get(position);
		final CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.check);
		checkBox.setText(em.getFullName());
		checkBox.setChecked(em.isChecked());
		checkBox.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				if (checkBox.isChecked()) {
					em.setChecked(true);
					listCheck.add(em);
				} else {
					em.setChecked(false);
					listCheck.remove(em);
				}
			}
		});
		return convertView;
	}
	public ArrayList<Employee> getEmlist() {
		return emlist;
	}
	public void setEmlist(ArrayList<Employee> emlist) {
		this.emlist = emlist;
	}
	public Context getContext() {
		return context;
	}
	public void setContext(Context context) {
		this.context = context;
	}
	public List<Employee> getListCheck() {
		return listCheck;
	}
	public void setListCheck(List<Employee> listCheck) {
		this.listCheck = listCheck;
	}
	public String getStrid() {
		strid="";
		if(listCheck.size()>0){
			for(int i=0;i<listCheck.size();i++){
				if(strid.equals("")){
					strid="'"+listCheck.get(i).getIdemployee()+"'";
				}else{
					strid+=",'"+listCheck.get(i).getIdemployee()+"'";
				}
			}
		}
		return strid;
	}
	public void setStrid(String strid) {
		this.strid = strid;
	}
	
}
